﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Bluyel.Core;

namespace Bluyel_Samples_VS10
{
    /// <summary>
    /// Code samples to see how to create var and const of basic types.
    /// </summary>
    public class Sample_VarConst_Basic
    {
        //---------------------------------------------------------------------
        /// <summary>
        /// Create 2 vars: an int and a bool.
        /// </summary>
        public void Create2Vars()
        {
            Console.WriteLine("\n----Create 2 vars:\n");

            // create the core and define all built-in types
            BluyelCore core = new BluyelCore();
            core.TypeBuilder.DefineAllTypes();

            // create var, int a=10, bool b=true
            DInt varA = core.DataBuilder.CreateVarInt("a", 10);
            DBool varB = core.DataBuilder.CreateVarBool("b", true);

            // display values fo the  vars
            Console.WriteLine("Create: " + varA.VarOrConst + " "+ varA.Type + " " + varA.Name + "=" + varA.Val);
            Console.WriteLine("Create: " + varB.VarOrConst + " " +varB.Type + " " + varB.Name + "=" + varB.Val);
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// create a const, try to change the value.
        /// </summary>
        public void CreateConstTryChangeVal()
        {
            Console.WriteLine("\n----Create a const, try to change a value:\n");

            // create the core and define all built-in types
            BluyelCore core = new BluyelCore();
            core.TypeBuilder.DefineAllTypes();

            // Create a const: int a=10
            DInt constA = core.DataBuilder.CreateConstInt("a", 12);
            Console.WriteLine("Create :" + constA.VarOrConst + " " + constA.Type + " " + constA.Name + "=" + constA.Val);

            // now set a value to the int: should failed!
            bool res = core.DataBuilder.SetVal(constA, 27);
            Console.WriteLine("Try to modify the constant: " + res);

            //// display values fo the  vars
            Console.WriteLine("So (no change): " + constA.VarOrConst + " " + constA.Type + " " + constA.Name + "=" + constA.Val);
        }

        //---------------------------------------------------------------------
        /// <summary>
        /// create a var and set a value later, and then change the value 
        /// </summary>
        public void CreateVarChangeSetVal()
        {
            Console.WriteLine("\n----Create a var, change the value:\n");

            // create the core and define all built-in types
            BluyelCore core = new BluyelCore();
            core.TypeBuilder.DefineAllTypes();

            // create a var: int a=10
            DInt varA = core.DataBuilder.CreateVarInt("a");

            // now set a value to the int
            core.DataBuilder.SetVal(varA, 27);

            // display values fo the  vars
            Console.WriteLine("Create : " + varA.VarOrConst + " " + varA.Type + " " + varA.Name + "=" + varA.Val);
        }


    }
}
